﻿using System;
using System.Web.UI;

using QuickDev.Model;

namespace QuickDev.Web.UI
{
    public class AdminPage : SitePage
    {
        #region Member Variables

        private AdminMasterPage _masterPage;

        #endregion

        #region Page Events

        /// <summary>
        /// Handles the PreInit event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_PreInit( object sender, EventArgs e )
        {
            string theme = "Default";
            if ( !string.IsNullOrEmpty( SiteSettings.Theme ) )
            {
                theme = SiteSettings.Theme;
            }
            this.Page.Theme = theme;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the name of the style sheet applied to this page.
        /// </summary>
        /// <value></value>
        /// <returns>The name of the style sheet applied to this page.</returns>
        /// <exception cref="T:System.InvalidOperationException">The <see cref="P:System.Web.UI.Page.StyleSheetTheme"/> property is set before the <see cref="E:System.Web.UI.Control.Init"/> event completes.</exception>
        public override string StyleSheetTheme
        {
            get
            {
                return SiteSettings.Theme;
            }
        }

        /// <summary>
        /// Gets the get master page.
        /// </summary>
        /// <value>The get master page.</value>
        private AdminMasterPage GetMasterPage { get { return Master as AdminMasterPage; } }

        /// <summary>
        /// Gets the base master page.
        /// </summary>
        /// <value>The base master page.</value>
        public AdminMasterPage BaseMasterPage
        {
            get
            {
                if ( _masterPage == null )
                    _masterPage = GetMasterPage;
                return _masterPage;
            }
        }

        #endregion
    }
}
